
const model = require('../schems')


let gbookAction={}




//所有评论
gbookAction.all = function(callback){
    return new Promise(function(resolve,reject){
        model.gbook.find({}).sort({createAt:-1}).exec(function(err,doc){
            if(err) return;
            resolve(JSON.parse(JSON.stringify(doc)))
          })
    })
}

//删除评论
gbookAction.deById = function(ids,callback){
  var idArr= ids.split(',') 
  model.gbook.deleteMany({'_id':{$in:idArr}},function(err,doc){
    if(err){
      console.log(err)
      return
    }
    console.log(doc)
    callback(doc)
  })
}

//保存留言
gbookAction.setGbook = function(obj){
    return new Promise(function(resolve,reject){
      let gbook = new model.gbook(obj)
      gbook.save().then(e=>{
        let doc = JSON.parse(JSON.stringify(e))
        resolve(doc)
      })
    })
  }




module.exports = gbookAction